﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using WpfControlDemo.Models;

namespace WpfControlDemo.ViewModels.控件.数据显示控件
{
    public class ListBoxWindowViewModel : INotifyPropertyChanged
    {
        public ObservableCollection<ClassModel> ClassModels { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public ListBoxWindowViewModel()
        {
            ClassModels = GetClassModel();
            houseList = new List<WaferInfo>();
            this.HouseList = GetShowWaferList();
        }

        /// <summary>
        /// 房屋列表
        /// </summary>
        private List<WaferInfo> houseList;
        public List<WaferInfo> HouseList
        {
            get
            {
                return houseList;
            }
            set
            {
                houseList = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(HouseList)));
            }
        }

        /// <summary>
        /// 获取晶圆集合
        /// </summary>
        /// <returns></returns>
        public List<WaferInfo> GetShowWaferList()
        {
            List<WaferInfo> infos = new List<WaferInfo>();
            for (int i = 1; i <= 25; i++)
            {
                infos.Add(new WaferInfo
                {
                    Status = "成功",
                    Name = $"晶圆名{i}",
                    ImageUrl = "pack://application:,,,/Zhy.CoaterDeveloper;component/Resource/Image/晶圆.jpg"
                });
            }
            return infos;
        }

        /// <summary>
        /// 此处模拟了数据库或者接口查询
        /// </summary>
        /// <returns></returns>
        public ObservableCollection<ClassModel> GetClassModel()
        {
            ObservableCollection<ClassModel> students = new ObservableCollection<ClassModel>();
            for (int i = 1; i <= 5; i++)
            {
                ClassModel studentModel = new ClassModel
                {
                    ClassId = i,
                    ClassName = $"{i}班"
                };
                students.Add(studentModel);
            }
            return students;
        }

        private ClassModel selectedItem;

        /// <summary>
        /// 获取与设置选中项
        /// </summary>
        public ClassModel SelectedItem
        {
            get { return selectedItem; }
            set
            {
                selectedItem = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedItem)));
            }
        }

        public void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var Item = (sender as System.Windows.Controls.ListBox).SelectedItem as ClassModel;
            var IListIListItems = (sender as System.Windows.Controls.ListBox).SelectedItems;
        }
    }
}
